package com.qf.controller;

import com.qf.pojo.CDList;
import com.qf.service.CDListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController("/cdlist")
public class CDListController {
    @Autowired
    CDListService cdListService;

    @RequestMapping("/findCDListAll")
    public List<CDList> findAll(){
       return cdListService.findAll();
    }

    @RequestMapping("/findCDListById")
    public CDList findById(@RequestBody Map map){
       Integer id= (Integer)map.get("id");
       return cdListService.findById(id);
    }

    @RequestMapping("/addAndUpdateCDList")
    public String addAndUpdate(CDList cdList){
        CDList cdList1 = cdListService.addAndUpdate(cdList);
        if(cdList1!=null){
            return "success";
        }else{
            return "fail";
        }
    }

    @RequestMapping("/deleteByCdid")
    public void delete(@RequestBody Map map){
        Integer id= (Integer)map.get("id");
        cdListService.delete(id);
    }
}
